﻿@model BBICMS.Model.Carousel
@{
    ViewBag.Title = "编辑轮播图";
    ViewBag.PageTitle = ViewBag.Title + "_组件";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";

    var options = new AjaxOptions()
    {
        Url = Url.Action("EditCarousel", "Carousel"),
        LoadingElementId = "saving",
        LoadingElementDuration = 2000,
        //   Confirm = "Are you sure you want to save this User?"
        OnSuccess = "updateSuccess"

    };
}


@section Header{
    <link href="~/plugins/SigFinder/SigFinder.min.css" rel="stylesheet" />
    <link href="~/plugins/webuploader/webuploader.css" rel="stylesheet" />
}



@using (Ajax.BeginForm("EditCarousel", null, new AjaxOptions()
            {
                HttpMethod = "POST",
                OnBegin = "onBeginSave",
                OnComplete = "onCompleteSave",

                OnSuccess = "updateSuccess"

            }, new { @class = "form-horizontal", role = "form" }))
            {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)


    @Html.HiddenFor(model => model.Id)
    @Html.HiddenFor(model => model.AddedBy)
    @Html.HiddenFor(model => model.AddedDate)
    @Html.HiddenFor(model => model.UpdatedBy)
    @Html.HiddenFor(model => model.UpdatedDate)
    <div class="panel panel-default">
        <header class="panel-heading">
           <span class="glyphicon glyphicon-edit"></span> @ViewBag.Title          
        </header>

        <section class="panel-body">

           

                <div class="form-group">
                    @Html.LabelFor(model => model.Title, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        @Html.TextBoxFor(model => model.Title, new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.Title, ViewData).Watermark })
                    </div>
                    <div class="col-md-5">
                        @Html.ValidationMessageFor(model => model.Title)
                    </div>
                </div>


    <div class="form-group">
        @Html.LabelFor(model => model.Description, new { @class = "col-md-2 control-label" })
        <div class="col-md-5">
            @Html.TextAreaFor(model => model.Description, new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.Description, ViewData).Watermark })
        </div>
        <div class="col-md-5">
            @Html.ValidationMessageFor(model => model.Description)
        </div>
    </div>


                <div class="form-group">
                    @Html.LabelFor(model => model.WebLink, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        @Html.TextBoxFor(model => model.WebLink, new { @class = "form-control", placeholder = "链接" })
                    </div>
                    <div class="col-md-5">
                        @Html.ValidationMessageFor(model => model.WebLink)
                    </div>
                </div>

                <div class="form-group">
                    @Html.LabelFor(model => model.Importance, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        @Html.TextBoxFor(model => model.Importance, new { @class = "form-control", type = "number", placeholder = "排序" })
                    </div>
                    <div class="col-md-5">
                        @Html.ValidationMessageFor(model => model.Importance)
                    </div>

                </div>

                <div class="form-group">
                    @Html.LabelFor(model => model.ImageUrl, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        <div class="input-group">
                            @Html.TextBoxFor(model => model.ImageUrl, new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.ImageUrl, ViewData).Watermark })
                            <span class="input-group-btn">
                                <button class="btn btn-default" id="btnThumbnail" type="button">浏览…</button>
                            </span>
                        </div><!-- /input-group -->
                    </div>
                    <div class="col-md-5">
                        @Html.ValidationMessageFor(model => model.ImageUrl)
                    </div>
                </div>


                <div class="form-group">

                    <div class="col-md-5 col-md-offset-2">
                        <div class="checkbox">
                            <label>
                                @Html.CheckBoxFor(model => model.Active)  @Html.DisplayNameFor(model => model.Active)
                            </label>
                        </div>

                    </div>
                    <div class="col-md-5">
                        @Html.ValidationMessageFor(model => model.Active)
                    </div>
                </div>
        </section>
        <footer class="panel-footer text-center">
            <button type="submit" class="btn btn-primary" id="btnSave"><i class="fa fa-save fa-fw"></i>  @Buttons.Update </button>
            <a href="@Url.Action("Index")" class="btn btn-default"><span class="glyphicon glyphicon-arrow-left"></span> @Buttons.Back</a>
        </footer>

    </div>

}

@Html.Action("PopuFinder", "File")

@section Footer {
   @Scripts.Render("~/bundles/jqueryvalWithBootstrap")
<script src="/Plugins/webuploader/webuploader.min.js"></script>
<script src="/Plugins/SigFinder/FileManager.js"></script>

    <script>
        function SetThumbnail() {
            var fileUrl = $("#fileList .item.active").attr("data-file");
            $('#ImageUrl').val(fileUrl);
            $('#fileManagerModal').modal('hide');
        }

        function onBeginSave() {
            $("#btnSave i").removeClass("fa-save").addClass("fa-spinner fa-spin");
        }
        function onCompleteSave() {
            $("#btnSave i").removeClass("fa-spinner fa-spin").addClass("fa-save");
        }


  function updateSuccess(data) {
        var title = '@ViewBag.Title';
        Common.ShowBox(data.Status, data.Message, title);
    }

    $(function () {
        $("#btnThumbnail").on("click", function () {
            $('#fileManagerModal').modal();
            $("#selectImage").unbind('click');
            $("#selectImage").bind("click", function () {
                SetThumbnail();
            });
        });

    });

    </script>
}
